package com.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import static android.R.attr.x;

public class MainActivity extends AppCompatActivity{
    int images[]=new int[]{
            R.drawable.a,R.mipmap.ic_launcher
    };
    int currentImg=0;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
        LinearLayout layout= (LinearLayout) findViewById(R.id.root);
        final ImageView imageView=new ImageView(this);
        layout.addView(imageView);
        imageView.setImageResource(images[0]);
        imageView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                imageView.setImageResource(images[++currentImg%images.length]);
            }
        });
    }


}
